package demo.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import demo.entity.*;
import demo.logger.LoggerHelper;

public class ServiceCard
{
	public static boolean addCard(String inName, String inType, int inCount)
	{

		Member member = new Member();
		int id = 0;
		ResultSet rs = member.queryIdByName(inName);
		try
		{
			rs.next();// 若没有重名
			id = Integer.parseInt(rs.getString(1));
		} catch (SQLException e)
		{
			System.out.println("没有查询到用户 " + inName + " 的数据");
			LoggerHelper.info("service.Card.add", "没有查询到用户 " + inName + " 的数据");
			// e.printStackTrace();
			return false;
		}

		if (inType.equals("年卡"))
		{
			CardYear cardyear = new CardYear();
			cardyear.setId(id);
			cardyear.save();

			System.out.println("OK. A new 年卡 added to " + inName + "(" + id
					+ ")");
			return true;
		} else if (inType.equals("次卡"))
		{
			CardTimes cardtimes = new CardTimes();
			cardtimes.setId(id);
			cardtimes.setCount(inCount);
			cardtimes.save();

			System.out.println("OK. A new 次卡　with " + inCount
					+ " times added to " + inName + " (" + id + ")");
			return true;

		} else
		{
			System.out.println("请输入正确的卡的类型!");
			LoggerHelper.debug("service.Card.add", "输入错误");
			return false;
		}
	}
}
